package testThread.service;

import testThread.database.DataBase;
import utils.C3P0Util;
import utils.ConnectionManager;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author xxx
 * @date 2021/1/12 11:42
 * @description
 */
public class ServiceDemo {
    public void accountService(String a,String b,double money) {
        Connection connection=null;
        try {

            connection= ConnectionManager.getConnection();

            ConnectionManager.setAutoCommit();

            DataBase dataBase=new DataBase();

            dataBase.out(a,money);

            System.out.println(1/0);

            dataBase.out(b,money);

            ConnectionManager.commit();

        } catch (SQLException e) {
            e.printStackTrace();
            try {
                    ConnectionManager.rollback();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
        }finally {
            C3P0Util.release(connection,null,null);
        }
        }

    }

